/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simplepushclient;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author Filip Lindqvist & Fredrik Persson
 */
public class Client {
    public static File saveFile;
    public static void main(String[] args){
        saveFile = new File(System.getenv("APPDATA"),"SimplePushIP.ini");
        String adress="192.168.0.1:1337";
        try {
            adress = loadAdress();
        } catch (Exception ex) {
            try {
                saveAdress(adress);
            } catch (FileNotFoundException ex1) {
                ex1.printStackTrace();
            } catch (IOException ex1) {
                ex1.printStackTrace();
            }
        }
        PusherTray p = new PusherTray(adress.split(":"));
        p.createTray();
    }
    public static void saveAdress(String adressString) throws FileNotFoundException, IOException{
        BufferedWriter bw = new BufferedWriter(new FileWriter(saveFile));
        for(char c : adressString.toCharArray()){
            bw.write(c);
        }
        bw.close();
    }
    public static String loadAdress() throws FileNotFoundException, IOException{
        BufferedReader br = new BufferedReader(new FileReader(saveFile));
        String s = "";
        int cha = 0;
        while(cha != -1 ){
            cha = br.read();
            if(cha!=-1){
                s+=(char)cha;
            }
        }
        br.close();
        return s;
    }
}